cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

if(MONGOC_VERSION_1)
    message(STATUS "Using mongoc version 1.x")
    set(MONGOC_CONFIG_NAME "mongoc-1.0")
else()
    message(STATUS "Using mongoc version 2.x or greater")
    set(MONGOC_CONFIG_NAME "mongoc")
endif()

find_package(${MONGOC_CONFIG_NAME} REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)

if(TARGET mongo::mongoc_shared)
    if(NOT TARGET mongoc::shared)
        message(FATAL_ERROR "Target 'mongoc::shared' does not exist")
    endif()
    if(NOT TARGET bson::shared)
        message(FATAL_ERROR "Target 'bson::shared' does not exist")
    endif()
    target_link_libraries(${PROJECT_NAME} PRIVATE mongo::mongoc_shared mongo::bson_shared)
else()
    if(NOT TARGET mongoc::static)
        message(FATAL_ERROR "Target 'mongoc::static' does not exist")
    endif()
    if(NOT TARGET bson::static)
        message(FATAL_ERROR "Target 'bson::static' does not exist")
    endif()
    target_link_libraries(${PROJECT_NAME} PRIVATE mongo::mongoc_static mongo::bson_static)
endif()
